﻿using System;
using PSE.Updater.Client.Engine;
using PSE.Updater.Common.Configurations.Client;
using PSE.Updater.Client.Providers;
using PSE.Updater.Common.Providers;
using PSE.Framework.ErrorLogging;

namespace PSE.Updater.Client.Wrapper
{
    /// <summary>
    /// Camada Base para interagir com o Server e efetuar a atualização do Sistema
    /// </summary>
    public class WrapperBase
    {
        public void Initialize(string systemPath)
        {
            if (string.IsNullOrEmpty(systemPath))
            {
                ErrorLogger.WriteLog(LogType.Error, new ArgumentNullException("systemPath"));
                return;
            }

            try
            {
                //UpdateBase configurationFile = new PSE.Updater.Client.Providers.ConfigurationFile.Update();
                //UpdateBase updates = new PSE.Updater.Client.Providers.ConfigurationFile.Update();
                //configurationFile.Initialize();
                //updates.Initialize();
                PSE.Updater.Common.Util.Instance.ExecuteSystem(systemPath, string.Empty, false);
            }
            catch (Exception ex)
            {
                ErrorLogger.WriteLog(LogType.Error, ex);
            }
        }

        /// <summary>
        /// Método que executa o sistema em questão.
        /// </summary>
        /// <param name="arguments">Parâmetros para Inicialização do Sistema</param>
        protected void OpenSystem(string systemPath)
        {
            PSE.Updater.Common.Util.Instance.ExecuteSystem(systemPath, string.Empty, false);

            //System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();

            //startInfo.FileName = systemPath;

            //startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
            //startInfo.CreateNoWindow = true;
            //startInfo.UseShellExecute = false;

            //System.Diagnostics.Process process = new System.Diagnostics.Process();
            //process.StartInfo = startInfo;
            //process.Start();
        }
    }
}
